package com.anthonybennis.blender.client.pages.keyboard;

import java.util.List;

import com.anthonybennis.blender.client.pages.keyboard.TilePanel.PANEL;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;

public class TileContainer
{
	private final TileDescriptionPanel _descriptionPanel;
	/**
	 * 
	 * @param panel
	 */
	public TileContainer(TileDescriptionPanel descriptionPanel)
	{
		_descriptionPanel = descriptionPanel;
	}
	
	protected Widget createWidget(PANEL panel) 
	{
		FlowPanel tileContainerPanel = new FlowPanel();
		
		tileContainerPanel.setStyleName("child-tile-panel");
		this.createTiles(tileContainerPanel, panel);
		
		return tileContainerPanel;
	}
	
	private int createTiles(FlowPanel tileContainerPanel, PANEL panel)
	{
		TileDataFactory factory = new TileDataFactory();
		List<String[]> tileDataList = factory.createTileData(panel);
		Tile tile;
		Widget tileWidget;
		for (String[] tileData : tileDataList) 
		{
			tile = new Tile(_descriptionPanel);
			tileWidget = tile.create(tileData);
			tileContainerPanel.add(tileWidget);
		}
		
		return tileDataList.size();
	}
}
